package com.sanhuo.idms.service;

import com.sanhuo.idms.dao.RoomMapper;
import com.sanhuo.idms.entity.Room;
import com.sanhuo.lib.ExceptionUtil;
import com.sanhuo.security.UserVo;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.Basic.BaseService;
import com.sanhuo.triild.annotation.MapperWire;
import com.sanhuo.utils.basic.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class RoomService extends BaseService<Room> {
    @MapperWire
    private RoomMapper roomMapper;

    @Override
    public BaseMapper<Room> getBaseMapper() {
        return roomMapper;
    }


    public void save(final UserVo user, Integer roomNum) {
        ExceptionUtil.throwException(roomMapper.countByNum(roomNum) > 0, "该房间(" + roomNum + ") 已存在,请不要重复添加!");
        Room room = new Room();
        room.setId(StringUtil.UUID());
        room.setNum(roomNum);
        room.creatorAndUpdatorInfo(user);
        save(room);
    }


}
